<template>
	<view>
		<!-- 用户信息表单 -->
		<form>
		<uni-forms :modelValue="user">
			<uni-forms-item label="用户名" name="username">
				<uni-easyinput type="text" v-model="user.username" disabled placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item label="密码" name="password">
				<uni-easyinput type="password" v-model="user.password" placeholder="请输入新密码" />
			</uni-forms-item>
			<uni-forms-item label="手机号" name="phone">
				<uni-easyinput type="text" v-model="user.phone" placeholder="请输入新手机号" />
			</uni-forms-item>
			<uni-forms-item label="收货地址" name="address">
				<uni-easyinput type="text" v-model="user.address" placeholder="请输入新收货地址" />
			</uni-forms-item>
			<uni-forms-item label="余额"  name="address">
				<uni-easyinput type="text" v-model="user.money" disabled />
			</uni-forms-item>
			<button :plain="false" @click="updateUserInfo()">修改信息</button>
			<button :plain="false" @click="back()">返回</button>
		</uni-forms>
		</form>
	</view>
</template>


<script>
	export default {
		data() {
			return {
				user: {
					username: uni.getStorageSync("token"),
					password:'',
					address:'',
					phone:'',
					money:'',
				},
			}
		},
		methods: {
			back(){
				uni.switchTab({
					url:'/pages/user/user'
				})
			},
			//修改个人信息
			updateUserInfo(){
				uni.request({
					url:'http://localhost:8081/user/updateUserInfo',
					data: this.user,
					method:'POST',
					success: (res) => {
						if(res.data.result){
							uni.showToast({
							    title: '修改成功',
							    duration: 2000
							});
						}
					}
				})
			}
		},
		onLoad() {
			//加载个人信息
			uni.request({
				url:'http://localhost:8081/user/selectOneUserByUsername?username='+this.user.username,
				success: (res) => {
					this.user=res.data.user;
				}
			})
		}
	}
</script>


<style>
</style>
